<template>
  <div class="mod-user">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()" class="data-form">
      <el-form-item>
        <el-input v-model="dataForm.keywords" placeholder="升级账号、升级用户、上级账号、上级名称、帮助升级者账号、帮助升级者名称" clearable style="width: 450px"></el-input>
      </el-form-item>
      <el-form-item>
        <el-select v-model="dataForm.pay" placeholder="支付类型" :value="dataForm.userType">
          <el-option key="1"  label="已支付" value="1"> </el-option>
          <el-option key="0"  label="未支付" value="0"> </el-option>
        </el-select>
      </el-form-item>
      <!-- <el-form-item>
        <el-date-picker
          value-format = "yyyy-MM-dd HH:mm:ss"
          v-model="dataForm.time"
          type="datetimerange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item> -->
      <el-form-item>
      <el-date-picker
          v-model="dataForm.startTime"
          type="datetime"
          value-format = "yyyy-MM-dd HH:mm:ss"
          placeholder="起始时间">
		</el-date-picker>
	  </el-form-item>
	  <el-form-item label="">
		<el-date-picker
          v-model="dataForm.endTime"
          type="datetime"
          value-format = "yyyy-MM-dd HH:mm:ss"
          placeholder="结束时间">
		</el-date-picker>
	  </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
        <el-button icon="el-icon-download" type="primary" @click="excel()">导出</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column
        prop="createTime"
        header-align="center"
        align="center"
        width="180"
        label="创建时间">
      </el-table-column>
      <el-table-column
        prop="upgradeMobile"
        header-align="center"
        align="center"
        width="150"
        label="升级账号">
      </el-table-column>
      <el-table-column
        prop="payTrueName"
        header-align="center"
        align="center"
        width="150"
        label="升级用户">
      </el-table-column>
      <el-table-column
        prop="passiveUserType"
        header-align="center"
        align="center"
        width="150"
        label="升级前类型">
        <template slot-scope="scope">
          <el-tooltip class="item" effect="dark" :content="memberType[scope.row.passiveUserType]" placement="top">
            <span class="characters">{{memberType[scope.row.passiveUserType]}}</span>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column
        prop="upgradeUserType"
        header-align="center"
        align="center"
        width="150"
        label="升级类型">
        <template slot-scope="scope">
          <el-tooltip class="item" effect="dark" :content="memberType[scope.row.upgradeUserType]" placement="top">
            <span class="characters">{{memberType[scope.row.upgradeUserType]}}</span>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column
        prop="isPay"
        header-align="center"
        align="center"
        width="150"
        label="支付状态">
        <template slot-scope="scope">
          <div v-if="scope.row.isPay != ''" style="color: forestgreen">{{scope.row.isPay? '已支付' : '未支付'}}</div>
          <div v-else="scope.row.isPay = ''" style="color: coral">{{scope.row.isPay? '已支付' : '未支付'}}</div>
          <!--{{scope.row.isPay? '以支付' : '未支付'}}-->
        </template>
      </el-table-column>
      <el-table-column
        prop="upgradeMoney"
        header-align="center"
        align="center"
        width="150"
        label="支付金额">
        <template slot-scope="scope">
          <span v-if="scope.row.upgradeMoney != null">￥ {{scope.row.upgradeMoney}}</span>
          <span v-if="scope.row.upgradeMoney == null">￥ 0</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="moneyType"
        header-align="center"
        align="center"
        width="150"
        label="升级场景">
        <template slot-scope="scope">
          <span v-if="scope.row.moneyType===0">扫码升级</span>
          <span v-else-if="scope.row.moneyType===1">平台升级</span>
          <span v-else-if="scope.row.moneyType===2">平台续费</span>
          <span v-else-if="scope.row.moneyType===3">线下交钱</span>
          <span v-else-if="scope.row.moneyType===4">后台降级</span>
          <span v-else-if="scope.row.moneyType===5">后台升级</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="givingIntegral"
        header-align="center"
        align="center"
        width="150"
        label="赠送现金券">
      </el-table-column>
      <!--<el-table-column
        prop="paNUserName"
        header-align="center"
        align="center"
        width="80"
        label="上级账号">
      </el-table-column>
      <el-table-column
        prop="paNUserTrueName"
        header-align="center"
        align="center"
        width="80"
        label="上级名称">
        <template  slot-scope="scope">
          <el-tooltip class="item" effect="dark" :content="scope.row.paNUserTrueName" placement="top">
            <span class="characters">{{scope.row.paNUserTrueName}}</span>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column
        prop="paNRealName"
        header-align="center"
        align="center"
        width="80"
        label="上级负责人">
      </el-table-column>
      <el-table-column
        prop="paNUserType"
        header-align="center"
        align="center"
        width="80"
        label="上级类型">
        <template  slot-scope="scope">
          <el-tooltip class="item" effect="dark" :content="memberType[scope.row.paNUserType]" placement="top">
              <span class="characters">{{memberType[scope.row.paNUserType]}}</span>
          </el-tooltip>
        </template>
      </el-table-column>-->
      <el-table-column
        prop="parUserName"
        header-align="center"
        align="center"
        width="150"
        label="帮助升级者账号">
      </el-table-column>
      <el-table-column
        prop="parTrueName"
        header-align="center"
        align="center"
        width="150"
        label="帮助升级者名称">
        <template  slot-scope="scope">
          <el-tooltip class="item" effect="dark" :content="scope.row.parRealName" placement="top">
            <span class="characters">{{scope.row.parRealName}}</span>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column
        prop="parRealName"
        header-align="center"
        align="center"
        width="160"
        label="帮助升级者负责人">
      </el-table-column>
      <el-table-column
        prop="recommUserType"
        header-align="center"
        align="center"
        label="推荐者用户类型">
        <template slot-scope="scope">
          <el-tooltip class="item" effect="dark" :content="memberType[scope.row.recommUserType]" placement="top">
            <span class="characters">{{memberType[scope.row.recommUserType]}}</span>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column
        prop="recommMoney"
        header-align="center"
        align="center"
        width="150"
        label="推荐奖励金额">
        <template slot-scope="scope">
          <span v-if="scope.row.recommMoney != null">￥ {{scope.row.recommMoney}}</span>
          <span v-if="scope.row.recommMoney == null">￥ 0</span>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
  </div>
</template>

<script>
import {typeName} from '@/utils/memberType'
export default {
  data () {
    return {
      dataForm: {
        keywords: '',
        pay: '',
        // time: new Date()
        startTime: '',
        endTime: ''
      },
      memberType: typeName,
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: []
    }
  },
  components: {
  },
  activated () {
    this.getDataList()
  },
  methods: {
      // 获取数据列表
    getDataList (getUserType, type) {
      console.log(this.memberType)
      debugger
      this.dataListLoading = true
      // this.$http({
      //   url: this.$http.adornUrl('/member/upgrade/queryUpgradeList'),
      //   method: 'get',
      //   params: this.$http.adornParams({
      //     'page': this.pageIndex - 1,
      //     'limit': this.pageSize,
      //     'keywords': this.dataForm.keywords,
      //     'getUserType': getUserType + 1,
      //     'pay': this.dataForm.pay,
      //     'lastStart': this.dataForm.startTime,
      //     'lastEnd': this.dataForm.endTime,
      //     'type': type + 1
      //   })
      // }).then(({data}) => {
      //   if (data && data.code === 0) {
      //     this.dataList = data.data.list
      //     this.totalPage = data.data.totalCount
      //     console.log(this.dataList)
      //   } else {
      //     this.dataList = []
      //     this.totalPage = 0
      //   }
      //   this.dataListLoading = false
      // })
      this.$http({
        url: this.$http.adornUrl('/member/upgrade/queryUpgradeList'),
        method: 'get',
        params: this.$http.adornParams({
          'page': this.pageIndex - 1,
          'limit': this.pageSize,
          'keywords': this.dataForm.keywords,
          'pay': this.dataForm.pay,
          'lastStart': this.dataForm.startTime,
          'lastEnd': this.dataForm.endTime
        })
      }).then(({data}) => {
        if (data && data.code === 0) {
          this.dataList = data.data.list
          this.totalPage = data.data.totalCount
          console.log(this.dataList)
        } else {
          this.dataList = []
          this.totalPage = 0
        }
        this.dataListLoading = false
      })
    },
      // 每页数
    sizeChangeHandle (val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },
      // 当前页
    currentChangeHandle (val) {
      this.pageIndex = val
      this.getDataList()
    },
      // 多选
    selectionChangeHandle (val) {
      this.dataListSelections = val
    },
      // 新增 / 修改
    addOrUpdateHandle (id) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(id)
      })
    },
    excel () {
      window.location.href = this.$http.adornUrl(`/member/upgrade/upgradeExcel?token=${this.$cookie.get('token')}&isPay=${this.dataForm.pay}&keywords=${this.dataForm.keywords}&pay=${this.dataForm.pay}&startTime=${this.dataForm.startTime}&endTime=${this.dataForm.endTime}`)
    }
  }
}
</script>
<style>
  .characters{
    width:300px;
    white-space:nowrap;
    overflow:hidden;
    text-overflow:ellipsis;
  }
</style>
